package com.le.test;

import org.junit.Test;

import java.util.Arrays;

public class Code_10_huanqian {

    public static int getNum(int aim) {
        if (aim < 0 || aim > 100) {
            throw new RuntimeException("aim is illegal arg");
        }
        int[] arr = {50, 10, 5, 1};
        return process(arr, 0, aim, 0);
    }

    public static int process(int[] arr, int i , int rest, int count) {
        if (i == arr.length) {
            return rest == 0 ? count : 0;
        }
        int res = Integer.MAX_VALUE;
        for (int zhang = 0; zhang * arr[i] <= rest; zhang++) {
            int k = process(arr, i + 1, rest - zhang * arr[i], count + zhang);
            if (k != 0) {
                res = Math.min(res, k);
            }
        }
        return res;
    }

    public static int[] generate(){
        int[] arr = new int[10];
        for (int i = 0; i < 10; i++) {
            arr[i] = (int)(Math.random() * 100) - 50;
        }
        return arr;
    }

    @Test
    public void test(){
        int[] res = generate();
        System.out.println(Arrays.toString(res));
        Arrays.sort(res);
        System.out.println(Arrays.toString(res));

    }
}
